<template>
  <el-container class="main_con">
    <div class="filter_con nopt">
      <div class="filter_area">
        <!-- <el-input class="serach_input mr_15" size="medium" placeholder="商品名称" style="width:300px;"></el-input> -->
        <el-input size="medium" v-model="obj.keyword" placeholder="请输入搜索内容" class="mr_15 mt_15" style="width:400px;">
          <el-select v-model="obj.type" slot="prepend" placeholder="请选择" style="width:130px;">
            <el-option v-for="item in type" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-input>

        <label class="mr_15 mt_15">支付方式</label>
        <el-select v-model="obj.pay_type" size="medium" placeholder="请选择" class="mr_15 mt_15">
          <el-option v-for="item in pay_type" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <label class="mr_15 mt_15">配送方式</label>
        <el-select v-model="obj.order_type" size="medium" placeholder="请选择" class="mr_15 mt_15">
          <el-option v-for="item in order_type" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <label class="mr_15 mt_15">订单类型</label>
        <el-select v-model="obj.order_from" size="medium" placeholder="请选择" class="mr_15 mt_15">
          <el-option v-for="item in fromlist" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>

        <!--  <label class="mr_15 mt_15">状态</label>
        <el-select v-model="obj.status" size="medium" placeholder="请选择" class="mr_15 mt_15">
          <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select> -->
        <div>
          <label class="mr_15 mt_15">创建时间</label>
          <date-picker size="medium" @change="getTime" class="mr_15 mt_15"></date-picker>
          <el-button class="mr_15 mt_15" @click="searchList" size="medium">搜索</el-button>
          <el-button v-has class="mr_15 mt_15" @click="exportorder" size="medium">导出</el-button>
        </div>
      </div>
    </div>
    <div class="list_con">
      <div class="orderlist">
        <div class="order_head">
          <table cellspacing="0" cellpadding="0" width="100%">
            <colgroup>
              <col />
              <col width="150" />
              <col width="180" />
              <col width="180" />
              <col width="180" />
              <col width="150" />
              <col width="130" />
              <col width="200" />
            </colgroup>
            <tbody>
              <tr>
                <td>商品</td>
                <td>单价/数量</td>
                <td>维权状态</td>
                <td>买家</td>
                <td>实付款</td>
                <td>支付/配送</td>
                <td>状态</td>
                <td>操作</td>
              </tr>
            </tbody>
          </table>
        </div>

        <div class="order" v-for="(item, i) in list" :key="i">
          <div class="header">
            <div class="txt">
              <div class="info" style="color: #2E68EA;">{{ item.order_from | getordertype }}</div>
              <div class="info">下单时间：{{ item.create_time }}</div>
              <div class="info">订单编号：{{ item.order_no }}</div>

              <div class="info"><el-button type="text" @click="doCopy(item.order_no)">复制</el-button></div>
              <div class="info">
                订单来源：
                <i title="微信小程序" v-if="item.source == 1" class="weixin el-sc-xiaochengxu"></i>
                <i title="微信公众号" v-if="item.source == 2" class="weixin el-sc-weixin4"></i>
                <i title="H5" v-if="item.source == 3" class="weixin el-sc-h5"></i>
              </div>
              <!--   <div class="info">支付流水号：{{ item.pay_no }}</div>
              <div class="info">内部单号：{{ item.unified_order_no }}</div> -->
              <div class="info">
                <el-tooltip placement="bottom-start">
                  <div class="one_line">
                    <span style="cursor: pointer">买家备注：{{ item.remake }}</span>
                  </div>
                  <div slot="content" style="width: 400px;line-height: 1.5;">买家备注： {{ item.remake }}</div>
                </el-tooltip>
              </div>
            </div>
            <div class="button">
              <el-button v-has v-if="jur_addons[10]" type="text" @click="printReceipt(item.id)">打印小票</el-button>
              <el-button v-has v-if="jur_addons[14] && item.order_type == 1" type="text" @click="toprint(item.order_no)">发货单</el-button>
              <el-button v-has v-if="jur_addons[14] && item.order_type == 1" type="text" @click="toprint(item.order_no)">电子面单</el-button>
            </div>
          </div>
          <div class="content">
            <table cellspacing="0" cellpadding="1" border="1" bordercolor="#dcdfe6" style="border-collapse:collapse;" width="100%">
              <colgroup>
                <col />
                <col width="150" />
                <col width="180" />
                <col width="180" />
                <col width="180" />
                <col width="150" />
                <col width="130" />
                <col width="200" />
              </colgroup>
              <tbody>
                <tr v-for="(sitem, l) in item.orderCommoditys" :key="l">
                  <td>
                    <div class="pro">
                      <div class="img"><vimage style="width: 80px; height: 80px;" :src="sitem.master" fit="fit"></vimage></div>
                      <div class="txt">
                        <div class="name">
                          <span :class="'t' + sitem.type">{{ sitem.type == 0 ? '实' : '虚' }}</span>
                          {{ sitem.name }}
                        </div>
                        <div class="class">{{ sitem.pvs_value_new }}</div>

                        <el-popover
                          placement="top-start"
                          title="附加规格
                        "
                          width="400"
                          trigger="hover"
                        >
                          <el-table :data="sitem.attachlist">
                            <el-table-column property="attach_value" label="附加"></el-table-column>
                            <el-table-column property="num" label="数量"></el-table-column>
                            <el-table-column property="attach_price" label="单价"></el-table-column>
                          </el-table>
                          <!--  <el-button >hover 激活</el-button> -->
                          <div slot="reference" v-if="sitem.attachlist && sitem.attachlist.length > 0">附加x{{ sitem.attachlist.length }},共￥{{ sitem.attach_pirce }}</div>
                        </el-popover>
                      </div>
                    </div>
                  </td>
                  <td>
                    ￥{{ sitem.sell_price }}
                    <br />
                    X{{ sitem.count }}
                  </td>

                  <td
                    v-if="item.after_type == 2 || item.orderCommoditys.length == 1 || l == 0"
                    :rowspan="item.after_type == 1 || !item.after_type ? item.orderCommoditys.length : 1"
                  >
                    <span>{{ sitem.after_type | after_status_text }}</span>
                    <span v-if="sitem.orderAfter">,{{ sitem.orderAfter.state_text }}</span>
                    <br />
                    <el-link v-if="sitem.after_status != '3' && sitem.order_after_id" :underline="false" type="primary" @click.stop="showAfter(sitem.order_after_id)">
                      维权详情
                    </el-link>
                  </td>

                  <td v-if="item.orderCommoditys.length == 1 || l == 0" :rowspan="item.orderCommoditys.length">
                    <el-tooltip v-if="item.order_type == 1" :content="'收货地址：' + item.address" placement="bottom-start">
                      <span style="cursor: pointer">
                        {{ item.user_real_name }}
                        <br />
                        {{ item.user_mobile }}
                      </span>
                    </el-tooltip>
                    <span style="cursor: pointer" v-else>
                      {{ item.user_real_name }}
                      <br />
                      {{ item.user_mobile }}
                    </span>
                  </td>
                  <td v-if="item.orderCommoditys.length == 1 || l == 0" :rowspan="item.orderCommoditys.length">
                    <el-popover placement="top" title="" width="170" trigger="hover">
                      <div class="pricecount">
                        <div>
                          <span>商品小计:</span>
                          <span>{{ item.orderItemCountPrice }}</span>
                        </div>
                        <div>
                          <span>运费:</span>
                          <span>￥{{ item.freight || '0.00' }}</span>
                        </div>
                        <div>
                          <span>优惠抵扣:</span>
                          <span>￥{{ item.discount || '0.00' }}</span>
                        </div>
                        <div>
                          <span>积分抵扣:</span>
                          <span>￥{{ item.discount_amount || '0.00' }}</span>
                        </div>

                        <div>
                          <span>会员折扣:</span>
                          <span>￥{{ item.discount_level_money }}</span>
                        </div>
                        <div>
                          <span>实付款:</span>
                          <span style=" color: #f56c6c;">￥{{ item.money }}</span>
                        </div>
                      </div>

                      <span slot="reference">
                        ￥{{ item.money }}
                        <br />
                        (含运费：￥{{ item.freight || '0.00' }})
                      </span>
                    </el-popover>
                  </td>
                  <!-- <td v-if="item.orderCommoditys.length == 1 || l == 0" :rowspan="item.orderCommoditys.length">后台确认<br/>快递</td> -->
                  <td v-if="item.orderCommoditys.length == 1 || l == 0" :rowspan="item.orderCommoditys.length">
                    {{ item.pay_id }}
                    <br />
                    {{ item.order_type | gettypetext }}
                  </td>
                  <td v-if="item.orderCommoditys.length == 1 || l == 0" :rowspan="item.orderCommoditys.length">
                    {{ item.status }}
                    <br />
                    {{ item.is_print }}
                    <br />
                    <span v-if="item.status == '已收货' || item.status == '已完结'">{{ item.is_evaluate ? '已评价' : '未评价' }}</span>
                  </td>
                  <td v-if="item.orderCommoditys.length == 1 || l == 0" :rowspan="item.orderCommoditys.length">
                    <el-button type="text" @click="showOrder(item.id)">查看详情</el-button>
                    <el-button v-has type="text" v-show="item.status == '待支付' && login_type_url != 'shop'" @click="changeState(item.id)">确认付款</el-button>
                    <el-button v-has type="text" v-show="item.status == '待支付'" @click="orderClose(item.id)">关闭订单</el-button>
                    <el-button v-has="'refund'" type="text" v-show="item.status == '待发货' || item.status == '待核销'" @click="orderdrawback(item.id)">退款</el-button>
                    <el-button v-has="'deliver'" type="text" v-show="(item.status == '待发货' || item.status == '部分发货') && item.order_type == 1" @click="toExpress(item)">
                      确认发货
                    </el-button>
                    <el-button v-has="'deliver'" type="text" v-show="(item.status == '待发货' || item.status == '部分发货') && item.order_type == 3" @click="toExpress(item, 1)">
                      确认发货
                    </el-button>
                    <el-button v-has="'deliver'" type="text" v-show="(item.status == '待支付' || item.status == '待发货') && item.order_type == 1" @click="changeAddress(item)">
                      修改收货信息
                    </el-button>
                    <el-button
                      v-has="'deliver'"
                      type="text"
                      v-show="item.orderCommoditys.findIndex(_ => _.status == '已发货') > -1 && item.order_type == 1 && login_type_url != 'shop'"
                      @click="cancalExpress(item, 0)"
                    >
                      取消发货
                    </el-button>
                    <el-button
                      v-has="'deliver'"
                      type="text"
                      v-show="item.orderCommoditys.findIndex(_ => _.status == '已发货') > -1 && item.order_type == 3 && login_type_url != 'shop'"
                      @click="cancalExpress(item, 1)"
                    >
                      取消发货
                    </el-button>
                    <el-button v-has type="text" v-show="item.status == '待支付'" @click="editMoneyShow(item.id)">改价</el-button>
                    <el-button v-has type="text" @click="changeMoneydetail(item.order_no)">改价详情</el-button>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>

        <div class="order_empty" v-if="list.length == 0">暂无数据</div>
      </div>
      <div class="table_footer" style="justify-content: flex-end;" v-if="total != 0">
        <el-pagination @current-change="changePage" class="pages" background hide-on-single-page layout="prev, pager, next" :total="total"></el-pagination>
      </div>
    </div>
    <el-dialog title="确认发货" destroy-on-close :visible.sync="showExpress" width="70%">
      <orderExpress :order="orderExpObj" @success="closeExpress" :key="rk"></orderExpress>
    </el-dialog>
    <el-dialog title="确认发货" destroy-on-close :visible.sync="showLocal" width="70%"><orderLocal :order="orderExpObj" @success="closeLocal" :key="dk"></orderLocal></el-dialog>
    <el-dialog title="修改收货地址" destroy-on-close :visible.sync="showAddress" width="500px">
      <orderAddress :order="orderAddressObj" @success="closeAddress" :key="rk"></orderAddress>
    </el-dialog>
    <el-dialog title="取消发货" destroy-on-close :visible.sync="showCancel" width="50%">
      <orderExpressCancel ref="cancelComponent" @success="cancelSuccess"></orderExpressCancel>
    </el-dialog>
    <el-dialog title="取消发货" destroy-on-close :visible.sync="showCancellocal">
      <orderLocalCancal ref="LocalcancelComponent" @success="cancelSuccess"></orderLocalCancal>
    </el-dialog>
    <el-dialog title="打印小票" :visible.sync="showPrintReceipt" width="30%" @close="clearDataRec" destroy-on-close>
      <div class="psoRec_item">
        <div class="label">选择模板：</div>
        <div class="content">
          <el-select size="medium" v-model="psoRec.template_id" placeholder="请选择模板">
            <el-option v-for="item in templateRecList" :key="item.id" :label="item.default ? item.name + '(默认)' : item.name" :value="item.id"></el-option>
          </el-select>
        </div>
      </div>

      <div class="psoRec_item">
        <div class="label">选择打印机：</div>
        <div class="content">
          <el-select size="medium" v-model="psoRec.printer_id" placeholder="请选择模板">
            <el-option v-for="item in templateList" :key="item.id" :label="item.default ? item.name + '(默认)' : item.name" :value="item.id"></el-option>
          </el-select>
        </div>
      </div>

      <el-button type="primary" size="medium" style="margin-left:15px" @click="printRecFun">打印数据</el-button>
    </el-dialog>
    <el-dialog title="商品改价" destroy-on-close :visible.sync="showMoneyEdit" width="30%">
      <changeMoney ref="orderMoneyEditComponent" @success="editMoneyClose"></changeMoney>
    </el-dialog>
  </el-container>
</template>

<script>
import DatePicker from '@/components/DatePicker/index';
import orderExpress from './components/orderExpress';
import orderAddress from './components/orderAddress';
import orderLocal from './components/orderLocal';
import orderExpressCancel from './components/orderExpressCancel';
import orderLocalCancal from './components/orderLocalCancal';
import changeMoney from './components/changeMoney';

import {delOrder, getOrderList, orderState, cancelExpress, orderdrawback, exportorder, orderClose} from '@/api/shop/order';
import {createReceipt, getReceiptTemplateList, getReceiptPrinterList} from '@/api/shop/print';
import {objextend} from '@/utils/index.js';
import {getToken, getShopToken, logintype_byurl} from '@/utils/auth';
export default {
  data() {
    return {
      showMoneyEdit: false,
      rk: 1,
      showCancel: false,
      expressCancel: {},
      showAddress: false,
      orderAddressObj: {},
      showExpress: false,
      orderExpObj: {},
      showLocal: false,
      showCancellocal: false,
      reasonslist: [],
      showPrintReceipt: false,
      templateRecList: [],
      templateList: [],
      jur_addons: {},
      cancalobj: {
        oid: '',
        id: 0,
        reason: ''
      },
      fromlist: [
        {
          value: '',
          label: '全部'
        },
        {
          value: '0',
          label: '普通订单'
        },
        {
          value: '1',
          label: '拼团订单'
        },
        {
          value: '2',
          label: '秒杀订单'
        },
        {
          value: '3',
          label: '预售订单'
        },
      ],
      type: [
        {
          value: '7',
          label: '订单编号'
        },
        {
          value: '1',
          label: '用户ID'
        },
        {
          value: '2',
          label: '用户信息'
        },
        {
          value: '3',
          label: '收件人信息'
        },
        {
          value: '4',
          label: '地址信息'
        },
        {
          value: '5',
          label: '商品名称'
        },
        {
          value: '6',
          label: '商品编号'
        }
      ],
      pay_type: [
        {
          value: '',
          label: '全部'
        },
        {
          value: 1,
          label: '余额'
        },
        {
          value: 2,
          label: '微信'
        },
        {
          value: 3,
          label: '支付宝'
        },
        {
          value: 4,
          label: '后台支付'
        }
      ],
      order_type: [
        {
          value: '',
          label: '全部'
        },
        {
          value: 1,
          label: '快递'
        },
        {
          value: 2,
          label: '自提'
        },
        {
          value: 3,
          label: '同城'
        }
      ],
      status: [
        {
          value: '',
          label: '全部'
        },
        {
          value: '1',
          label: '待支付'
        },
        {
          value: '2',
          label: '待发货'
        },
        {
          value: '13',
          label: '待核销'
        },
        {
          value: '3',
          label: '已发货'
        },
        {
          value: '4',
          label: '已完结'
        },
        // {
        //   value: '5',
        //   label: '已评价'
        // },
        // {
        //   value: '6',
        //   label: '已删除'
        // },
        // {
        //   value: '7',
        //   label: '部分发货'
        // },
        {
          value: '8',
          label: '已收货'
        },
        // {
        //   value: '9',
        //   label: '部分收货'
        // },
        {
          value: '10',
          label: '维权中'
        },
        {
          value: '11',
          label: '维权完成'
        },
        {
          value: '12',
          label: '已关闭'
        }
      ],
      obj: {
        //name:'',
        type: '7',
        keyword: '',
        pay_type: '',
        status: '',
        start_time: '',
        end_time: '',
        page: 1,
        size: 10,
        order_type: '',
        order_from: ''
      },
      objTemp: {},
      total: 0,
      isLoading: false,
      list: [],
      psoRec: {
        order_id: [],
        printer_id: '',
        template_id: ''
      },
      login_type: '',
      login_type_url: '',
      dk: 1
    };
  },
  components: {
    DatePicker,
    orderExpress,
    orderAddress,
    orderLocal,
    orderExpressCancel,
    orderLocalCancal,
    changeMoney
  },
  filters: {
    after_status_text: function(value) {
      switch (value) {
        case 1:
          return '仅退款';
          break;
        case 2:
          return '退货退款';
          break;
        case 3:
          return '换货';
          break;
        default:
          return '-';
          break;
      }
    },
    getordertype(val) {
      switch (val) {
        case 0:
          return '普通订单';
          break;
        case 1:
          return '拼团订单';
          break;
        case 2:
          return '秒杀订单';
          break;
          case 3:
            return '预售订单';
            break;
        default:
          return '-';
          break;
      }
    },
    gettypetext(val) {
      switch (val) {
        case 1:
          return '快递';
          break;
        case 2:
          return '自提';
          break;
        case 3:
          return '同城';
          break;
        default:
          return '-';
          break;
      }
    }
  },
  created() {
    this.$jur_addons([10, 14]).then(a => {
      this.jur_addons = a;
    });
    this.login_type_url = logintype_byurl();
    if (this.$route.meta && this.$route.meta.status) {
      this.obj.status = this.$route.meta.status;
    }
    if (this.$route.query.status) {
      this.obj = objextend(this.obj, this.$route.query);
    }
    if (this.$route.query.type) {
      // this.$route.query.type=Number(this.$route.query.type)
      this.obj = objextend(this.obj, this.$route.query);
    }
    this.login_type = localStorage.getItem('login_type');
    this.getTemplateList();
    this.getTemplateRecList();
  },
  mounted() {
    this.searchList();
  },
  methods: {
    //显示变更余额
    editMoneyShow(id) {
      this.showMoneyEdit = true;
      this.$nextTick(_ => {
        this.$refs.orderMoneyEditComponent.init(id);
      });
    },
    //关闭变更余额回调
    editMoneyClose() {
      //重新加载数据
      this.showMoneyEdit = false;
      this.getDataList();
    },

    //导出订单
    exportorder() {
      if (localStorage.getItem('login_type') == 'mall') {
        var Authorization = getShopToken();
      } else {
        var Authorization = getToken();
      }
      // Authorization
      let data = this.objTemp;
      if (data.status == '13') {
        data.status = '2';
        data.order_type = 2;
      } else {
        // this.objTemp.order_type=''
      }
      var url = `/shop/order/export?type=${data.type}&keyword=${data.keyword}&pay_type=${data.pay_type}&start_time=${data.start_time}&end_time=${data.end_time}&status=${
        data.status
      }&Authorization=${Authorization}`;
      if (data.order_type) {
        url += `&order_type=${data.order_type}`;
      }
      window.location.href = url;
    },
    orderdrawback(id) {
      this.$confirm('是否直接退款？').then(_ => {
        // this.isLoading = true;
        orderdrawback({oid: id}).then(res => {
          // this.isLoading = false;
          this.getDataList();
        });
      });
    },

    //取消发货
    cancalExpress(data, type) {
      let id = data.id;

      if (type == 1 && data.dada && data.dada.length > 0) {
        this.showCancellocal = true;
        this.$nextTick(_ => {
          this.$refs.LocalcancelComponent.init(id);
        });
      } else {
        this.showCancel = true;
        this.$nextTick(_ => {
          this.$refs.cancelComponent.init(id);
        });
      }
    },
    //取消发货回调
    cancelSuccess() {
      this.showCancel = false;
      this.showCancellocal = false;
      this.getDataList();
    },
    //查看维权详情
    showAfter(id) {
      this.$router.push({path: '/order/list/afterItem', query: {id: id, k: Math.random()}});
    },
    //修改订单状态(临时,测试用,将订单改成'已付款'状态)
    changeState(id) {
      this.$confirm('是否直接修改订单状态为"已支付"?')
        .then(_ => {
          let o = {};
          o.id = id;
          o.status = 2;
          this.isLoading = true;
          orderState(o).then(res => {
            this.isLoading = false;
            this.getDataList();
          });
        })
        .catch({
          //empty
        });
    },
    //修改收货信息
    changeAddress(item) {
      this.orderAddressObj = item;
      this.rk++;
      this.showAddress = true;
    },
    //修改收货信息回调
    closeAddress() {
      this.showAddress = false;
      this.getDataList();
    },
    //确认发货
    toExpress(item, type) {
      this.orderExpObj = Object.assign({}, item);
      if (type) {
        this.showLocal = true;
        this.dk++;
      } else {
        this.$set(this.orderExpObj, 'cids', []);
        this.$set(this.orderExpObj, 'logistics_no', '');
        this.$set(this.orderExpObj, 'express_company', '');

        this.showExpress = true;
        this.rk++;
      }
    },
    //发货回调函数
    closeExpress() {
      this.showExpress = false;
      this.getDataList();
    },
    //发货回调函数
    closeLocal() {
      this.showLocal = false;
      this.getDataList();
    },

    //复制单号
    doCopy(orderNo) {
      this.$copyText(orderNo).then(
        res => {
          //this.$alert('复制成功');
          this.$message({
            message: '复制成功',
            type: 'success',
            duration: 2000
          });
        },
        error => {
          this.$alert('无法复制');
        }
      );
    },
    //获取时间
    getTime(value) {
      this.obj.start_time = value[0];
      this.obj.end_time = value[1];
    },
    //查询数据
    searchList() {
      //复制查询对象
      this.objTemp = Object.assign({}, this.obj);
      this.getDataList();
    },
    //查询数据本体
    getDataList() {
      this.isLoading = true;
      if (this.objTemp.status == '13') {
        this.objTemp.status = '2';
        this.objTemp.order_type = 2;
      } else {
        // this.objTemp.order_type=''
      }
      if (!this.objTemp.order_type) {
        delete this.objTemp.order_type;
      }
      getOrderList(this.objTemp)
        .then(res => {
          this.isLoading = false;
          let o = res.msg;
          //处理sku规格数据
          o.data.forEach(e => {
            if (e.order_type == 3) {
              // e.money = Number(e.money) - Number(e.distribution_fee);
              e.freight = e.distribution_fee.toFixed(2);
            }
            if (e.orderCommoditys.length > 0) {
              e.orderItemCountPrice = 0;
              e.orderCommoditys.forEach(x => {
                if (x.pvs_value) {
                  //转换处理SKU数据->红+L+大
                  let l = x.pvs_value.split(','),
                    s = '';
                  l.forEach(k => {
                    s += k.split(':')[1] + '+';
                  });
                  s = s.substring(0, s.length - 1);
                  x.pvs_value_new = s;
                }
                e.orderItemCountPrice += x.sell_price * x.count;
                if (e.attach && e.attach.length > 0 && x.attach_value && x.attach_value != '') {
                  x.attachlist = [];
                  x.attach_pirce = 0;

                  e.attach.forEach(a => {
                    if (x.attach_value.indexOf(a.attach_value) > -1 && x.attachlist.findIndex(_ => _.attach_value == a.attach_value) == -1) {
                      if (x.sku_id) {
                        if (x.sku_id == a.sku_id) {
                          x.attachlist.push(a);
                          x.attach_pirce += Number(a.attach_price) * a.num;
                        }
                      } else {
                        x.attachlist.push(a);
                        x.attach_pirce += Number(a.attach_price) * a.num;
                      }
                    }
                  });
                  e.orderItemCountPrice += x.attach_pirce;
                  x.attach_pirce = x.attach_pirce.toFixed(2);
                }
              });
            }
            e.orderItemCountPrice = e.orderItemCountPrice.toFixed(2);
            if (e.status == '待发货' && e.order_type == 2) {
              e.status = '待核销';
            }
          });
          this.list = o.data;
          this.total = o.total;
        })
        .catch(e => {
          this.isLoading = false;
        });
    },
    //查看订单详情
    showOrder(id) {
      this.$router.push({path: '/order/list/item', query: {id: id, k: Math.random()}});
    },
    changeMoneydetail(id) {
      this.$router.push({path: '/order/list/c_m_list', query: {id: id, k: Math.random()}});
    },

    //获取所有打印模板(小票)
    getTemplateRecList() {
      getReceiptTemplateList()
        .then(res => {
          this.templateRecList = res.msg;
        })
        .catch(e => {
          //empty
        });
    },
    //获取所有打印模板
    getTemplateList() {
      getReceiptPrinterList()
        .then(res => {
          this.templateList = res.msg;
        })
        .catch(e => {
          //empty
        });
    },
    printReceipt(id) {
      let order_id = [];
      order_id.push(id);
      this.psoRec.order_id = order_id;
      this.showPrintReceipt = true;
    },
    //打印小票关闭自动清空模板选择数据
    clearDataRec() {
      this.psoRec.template_id = '';
      this.psoRec.printer_id = '';
    },
    //打印小票
    printRecFun() {
      if (this.psoRec.template_id && this.psoRec.printer_id) {
        createReceipt(this.psoRec)
          .then(res => {
            this.$message({
              message: '操作完毕,请等待打印结果',
              type: 'success'
            });
            this.showPrintReceipt = false;
          })
          .catch(e => {
            //empty
          });
      } else {
        this.$alert('请先选择打印模板与打印机');
        return false;
      }
    },
    //打印面单
    toprint(order_no) {
      let routeUrl = this.$router.resolve({
        path: '/print/list',
        query: {order_no: order_no}
      });
      window.open(routeUrl.href, '_blank');
    },
    //删除数据
    delItem(id) {
      this.$confirm('是否要删除该条数据?').then(_ => {
        this.isLoading = true;
        delOrder(id)
          .then(res => {
            this.isLoading = false;
            //重新加载数据
            this.getDataList();
          })
          .catch(e => {
            this.isLoading = false;
          });
      });
    },
    orderClose(id) {
      this.$confirm('是否要关闭该订单?').then(_ => {
        this.isLoading = true;
        orderClose({id: id})
          .then(res => {
            this.isLoading = false;
            //重新加载数据
            this.getDataList();
          })
          .catch(e => {
            this.isLoading = false;
          });
      });
    },
    //切换分页
    changePage(page) {
      this.objTemp.page = page;
      this.getDataList();
    }
  }
};
</script>

<style lang="scss" scoped>
// .list_con{
//   overflow-x: hidden;
// }
// .orderlist{
//   min-width: 1400px;
// }
.one_line {
  width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.proImg {
  display: flex;
  align-items: center;
}
.psoRec_item {
  display: flex;
  align-items: center;
  margin-bottom: 22px;

  .label {
    width: 100px;
    text-align: right;
  }

  .content {
    flex-grow: 1;
  }
}
//订单列表
.orderlist {
  width: 100%;
  display: flex;
  flex-direction: column;

  .order_head {
    border-bottom: 1px solid #dcdfe6;
    font-weight: 700;
    color: #909399;
    font-size: 14px;

    table {
      tr {
        td {
          padding: 10px 20px 20px;
          // text-align: center;
        }
      }
    }
  }

  .order_empty {
    color: #c0c4cc;
    font-size: 14px;
    text-align: center;
    height: 50px;
    line-height: 50px;
  }

  .order {
    margin-top: 15px;

    &:first-child {
      margin-top: 0;
    }

    .header {
      background-color: #f4f6f8;
      height: 40px;
      line-height: 40px;
      display: flex;
      border: 1px solid #dcdfe6;
      border-bottom: 0;
      padding-left: 20px;
      color: #909399;
      font-size: 14px;

      .txt {
        flex: 1;
        display: flex;
        .info {
          display: inline-block;
          margin-right: 15px;
        }
      }

      .button {
        width: 200px;
        text-align: right;
        padding-right: 20px;
      }
    }

    .content {
      background: #dcdfe6;
      font-size: 14px;
      color: #606266;

      table {
        background: #fff;

        tr {
          td {
            padding: 17px 17px 0 17px;
            line-height: 28px;
            //border: 1px solid #DCDFE6;
            border: none;
            .pro {
              display: flex;

              .img {
                width: 80px;
                height: 80px;
                margin-right: 10px;
              }

              .txt {
                flex: 1;
                display: flex;
                flex-direction: column;
                align-content: space-between;

                .name {
                  text-overflow: -o-ellipsis-lastline;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  display: -webkit-box;
                  -webkit-line-clamp: 2;
                  line-clamp: 2;
                  -webkit-box-orient: vertical;
                  .t0 {
                    color: #409eff;
                    font-weight: 700;
                    margin-right: 5px;
                  }

                  .t1 {
                    color: #f56c6c;
                    font-weight: 700;
                    margin-right: 5px;
                  }
                }
                .class {
                  width: 50%;
                  word-break: break-all;
                  text-overflow: ellipsis;
                  overflow: hidden;
                  display: -webkit-box;
                  -webkit-line-clamp: 2;
                  -webkit-box-orient: vertical;
                }
              }
            }
          }
          &:last-child {
            td {
              padding: 17px;
            }
          }
        }
      }
    }
  }
}
.pricecount {
  div {
    padding: 5px 0;
    span:first-child {
      display: inline-block;
      width: 75px;
      text-align: right;
      margin-right: 5px;
    }
  }
}
</style>
